<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field site-demo-button">
        <legend>订单信息</legend>
        <table class="layui-table layui-table-add" lay-skin="nob">
            <tbody>
            <tr>
                <th width="100" class="pad">订单编号</th>
                <td>{$order.sn}</td>
            </tr>
            <tr>
                <th class="pad">订单状态</th>
                <td>{$order.order_cn}  </td>
            </tr>
            <?php if($order['px_status']==2): ?>
            <tr>
                <th class="pad">推送失败原因</th>
                <td>{$order.px_error}  </td>
            </tr>
            <?php endif; ?>
            <tr>
                <th class="pad">创建时间</th>
                <td>{:date('Y-m-d H:i:s',$order['create_time'])}</td>
            </tr>
            </tbody>
        </table>
    </fieldset>

    <fieldset class="layui-elem-field site-demo-button">
        <legend>收货信息</legend>
        <table class="layui-table layui-table-add" lay-skin="nob">
            <tbody>
            <tr>
                <th width="100" class="pad">会员ID</th>
                <td>{$order.uid}</td>
            </tr>
            <tr>
                <th class="pad">姓名</th>
                <td>{$order.first_name} {$order.last_name}</td>
            </tr>
            <tr>
                <th class="pad">手机号码</th>
                <td>{$order.phone}</td>
            </tr>
            <tr>
                <th width="100" class="pad">邮箱</th>
                <td>{$order.email}</td>
            </tr>
            <tr>
                <th class="pad">州</th>
                <td>{$order.state}</td>
            </tr>
            <tr>
                <th class="pad">城市</th>
                <td>{$order.city}</td>
            </tr>
            <tr>
                <th class="pad">邮编</th>
                <td>{$order.post_code}</td>
            </tr>
            <tr>
                <th class="pad">地址1</th>
                <td>{$order.addr1}</td>
            </tr>
            <tr>
                <th class="pad">地址2</th>
                <td>{$order.addr2}</td>
            </tr>
            </tbody>
        </table>
    </fieldset>

    <fieldset class="layui-elem-field layui-field-title mtb10">
        <legend>商品信息</legend>
    </fieldset>
    <table class="layui-table" lay-skin="line">
        <thead>
        <tr>
            <th colspan="2">商品名称</th>
            <th>单价</th>
            <th>数量</th>
            <th>小计</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name='order_data' id='vo'}
        <tr>
            <td width="66" class="a3"><img class="img-cp" src="{$vo.product_pic}" alt=""></td>
            <td width="300" class="a3">
                {$vo.product_title}
            </td>
            <td>{$vo.product_price}</td>
            <td>
                <input type="text" style="height: 30px;width:50px;text-align: center"      value="{$vo.num}">
                <span style="background:#337ab7;padding: 10px;color:white" onclick="orderedit(this)" data-id="{$vo.id}" >修改</span>
            </td>
            <td>{$vo.price}</td>
            <td> <span style="background: red;padding: 10px;" onclick="orderdel(this)" data-id="{$vo.id}" >删除</span></td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>

    <fieldset class="layui-elem-field site-demo-button">
        <legend>资金信息</legend>
        <table class="layui-table layui-table-add" lay-skin="nob">
            <tbody>
            <tr>
                <th width="100" class="pad">商品总金额</th>
                <td>{$order.goods_total}</td>
            </tr>
            <tr>
                <th class="pad">订单总金额</th>
                <td>{$order.order_total}</td>
            </tr>
            </tbody>
        </table>
    </fieldset>

    <?php if($order['px_status'] != 1): ?>
    <fieldset class="layui-elem-field site-demo-button">
        <legend>4px发货</legend>
        <table class="layui-table layui-table-add" lay-skin="nob">
            <tbody>
            <tr>
                <th width="100" class="pad">物流选择</th>
                <td>
                    <select id="fahuo_type">
                        <?php if($wuliu_list): foreach($wuliu_list as $wuliu): ?>
                        <option value="<?php echo $wuliu['logistics_product_code']; ?>"><?php echo $wuliu['logistics_product_name_cn']; ?></option>
                        <?php endforeach;endif; ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <a class="layui-btn"  onclick="fahuo(this)"   data-id="<?php echo $order['id'] ?>" >发货</a>
                </td>
            </tr>
            </tbody>
        </table>
    </fieldset>
    <?php endif; ?>
</div>

<script type="text/html" id="name">
    {{d.first_name}} {{d.last_name}}
</script>
<script type="text/html" id="action">
    <a href="{:url('admin/order/show')}?id={{d.id}}" class="layui-btn layui-btn-xs layui-btn-normal">管理</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        var tableIn = table.render({
            id: 'content',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            toolbar: '#topBtn',
            page: true,
            cols: [[
                //{type: "checkbox", fixed: true},
                {field: 'id', title: '{:lang("id")}', width: 80, fixed: true},
                {field: 'sn', title: '单号', width: 200},
                {field: 'order_cn', title: '状态', width: 200},
                {field: 'order_total', title: '金额', width: 100},
                {field: 'title', title: '姓名', width: 100, templet: '#name'},
                {field: 'phone', title: '电话', width: 150},
                {field: 'addr1', title: '地址1', width: 200},
                {field: 'addr2', title: '地址1', width: 200},
                {field: 'create_time', title: '{:lang("add")}{:lang("time")}', width: 180},
                {fixed:'right',width: 160, align: 'center', toolbar: '#action',title:'操作'}
            ]],
            limit: 10
        });
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            if ($.trim(key) === '') {
                layer.msg('{:lang("pleaseEnter")}关键字！', {icon: 0});
                return;
            }
            tableIn.reload({ page: {page: 1}, where: {key: key}});
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除该内容吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('listDel')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload({where:{catid:'{:input("catid")}'}});
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            if(obj.event === 'tuisong'){
                layer.confirm('您确定要推送吗', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#aabbcc']});
                    $.post("{:url('pxPush')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload({where:{catid:'{:input("catid")}'}});
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
    function fahuo(e) {
        var id = $(e).attr("data-id");
        var fahuo_type = $("#fahuo_type").val();
        if(fahuo_type<1){
            layer.msg('请选择物流方式',{time:1000,icon:2});
            return false;
        }
        layer.confirm('您确定要推送吗', function(index){
            var loading = layer.load(1, {shade: [0.1, '#abc']});
            $.post("{:url('pxPush')}",{id:id,fahuo_type:fahuo_type},function(res){
                layer.close(loading);
                if(res.code===1){
                    layer.msg(res.msg,{time:1000,icon:1});
                    location.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    location.reload();
                }
            });
            layer.close(index);
        });
    }

    function orderedit(e) {
        var id = $(e).attr('data-id');
        console.log(id);
        var num =$(e).prev().val();
        console.log(num);


        $.post("{:url('orderGoodsEdit')}",{order_goods_id:id,num:num},function(res){
            if(res.code===1){
                layer.msg(res.msg,{time:1000,icon:1});
                location.reload();
            }else{
                layer.msg(res.msg,{time:1000,icon:2});
            }
        });
    }
    function orderdel(e) {
        var id = $(e).attr('data-id');
        console.log(id);
        if(confirm("确定要删除吗?")==true){
            $.post("{:url('orderGoodsDel')}",{order_goods_id:id},function(res){
                if(res.code===1){
                    layer.msg(res.msg,{time:1000,icon:1});
                    location.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        }
    }

</script>